/**
 * 
 * @authors youzhao.zhou@pandauu.com
 * @date    2016-09-05 11:23:28
 * @version $Id$
 * 自有DOM操作库
 * 
 * 
 */


;(function(root,factory){

  if(typeof exports === 'object' && typeof module === 'object'){

    module.exports = factory(exports);

  } else if (typeof define === 'function' && define.amd) {
    // AMD. Register as an anonymous module.
    define(['exports'], factory);
  } else if (typeof exports === 'object' && typeof exports.nodeName !== 'string') {
    // CommonJS
    factory(exports);
  } else {
    // Browser globals
    root._$ = factory({});
  }

})((typeof window !== 'undefined' ? window : this) ,function(exports, undefined){
  'use strict';
  /*
    调试代码
  */
  var _logClose = true;

  function _log(msg) {
    if (typeof console !== 'undefined'&&_logClose) {
      
      return console && console.error && console.error(msg);
    }
  };


  var _$ = function( selector, context ) {

    return new _$.init( selector, context );
  };

  _$.init = function( selector, context){
    var dom = null;

    if ('querySelector' in document) {
      dom = document.querySelectorAll(selector);
      
      if (!!!dom||dom.length == 1) {
        this[0] = document.querySelector(selector);
      }else if(dom.length > 1){
        this[0] = dom;
      }else{
        this[0] = document.querySelector('html');
      }
    }else{
      alert('您的浏览器不支持该框架');
      throw('您的浏览器不支持该框架');
    }
    return this;
  };
  /*
    调试开关
  */
  _$._logToggle = function (toggle) {
    _logClose = toggle;
  };
  /*
    CSS样式
  */
  _$.prototype.css = function (obj) {
    if (typeof obj !== 'object') {
      throw('css函数接受输入json对象！！');
      return false;
    }
    console.log(this);
    for(var k in this[0]){
      if (this[0].hasOwnProperty(k)) {
        for(var m in obj){
          this[0][k].style[m] = obj[m];
        }
      }
    }

  };
  /*
    Ajax请求
  */
  _$.ajax = function(){

  };
  /*
    添加事件
  */
  _$.prototype.addEvent = function (toggle) {
    _log(123);
  };
  /*
    移除事件
  */
  _$.prototype.removeEvent = function (toggle) {
    _log(123);
  };

  _$.prototype._logToggle1 = function (toggle) {
    _log(123);
  };

  _$.init.prototype = _$.prototype;


  return _$;
});